{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_modify bootstrapped_goodies_tags %}
{% load form_helpers %}
{% load helpers %}

{% block extrahead %}{{ block.super }}
    {% url 'admin:jsi18n' as jsi18nurl %}
    <script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
    {{ media }}
{% endblock %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %}

{% if not is_popup %}
    {% block breadcrumbs %}
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{% url 'admin:index' %}">{% trans 'Admin Home' %}</a></li>
            <li class="breadcrumb-item">
                <a href="{% url 'admin:app_list' app_label=opts.app_label %}">
                    {% with app_label=opts.app_config.verbose_name|default:opts.app_label %}{{ app_label|title }}{% endwith %}
                </a>
            </li>
            <li class="breadcrumb-item">
                {% if has_change_permission %}
                    <a href="{% url opts|admin_urlname:'changelist' %}">
                        {{ opts.verbose_name_plural|capfirst }}
                    </a>
                {% else %}
                    {{ opts.verbose_name_plural|capfirst }}
                {% endif %}
            </li>
            <li class="breadcrumb-item active" aria-current="page">{% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}</li>
        </ol>
    {% endblock %}
{% endif %}

{% block object-tools %}
    {% if change %}
        {% if not is_popup %}
            <div id="content-navbar-collapse" class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    {% block object-tools-items %}
                        <li>
                            {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
                            <a role="button" href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
                        </li>
                        {% if has_absolute_url %}
                            <li>
                                <a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">
                                    {% trans "View on site" %}
                                </a>
                            </li>
                        {% endif %}
                    {% endblock %}
                </ul>
            </div>
        {% endif %}
    {% endif %}
{% endblock %}

{% block content %}

    {% with module_name=opts.model_name|lower|slugify %}
        {% render_with_template_if_exist opts.app_label|lower|add:"/admin_model_"|add:module_name|add:"_change_form.html" "" %}
    {% endwith %}


    <form class="form-horizontal" {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>
        {% csrf_token %}
        {% block form_top %}{% endblock %}

        <div class="alert alert-warning">{% blocktrans %}Fields in <strong>bold</strong> are required.{% endblocktrans %}</div>
        {% if errors %}
            <div class="alert alert-danger">
                {% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
                {{ adminform.form.non_field_errors }}
            </div>
        {% endif %}

        {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}

        <div id="content-main" class="row">
            <div {% if is_popup %}class="col-lg-12"{% else %}class="col-lg-6 offset-lg-3"{% endif %}>
                {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
                {% block field_sets %}
                    {% for fieldset in adminform %}
                        {% include "admin/includes/fieldset.html" with group_column_width=adminform|form_fieldset_column_width %}
                    {% endfor %}
                {% endblock %}

                {% block after_field_sets %}{% endblock %}

                {% block inline_field_sets %}
                    {% for inline_admin_formset in inline_admin_formsets %}
                        {% include inline_admin_formset.opts.template %}
                    {% endfor %}
                {% endblock %}

                {% block after_related_objects %}{% endblock %}

                {% block admin_change_form_document_ready %}

                    <script type="text/javascript">
                        (function($) {
                            $(document).ready(function() {
                                $('.add-another').click(function(e) {
                                    e.preventDefault();
                                    showAddAnotherPopup(this);
                                });
                                $('.related-lookup').click(function(e) {
                                    e.preventDefault();
                                    showRelatedObjectLookupPopup(this);
                                });
                                {% if adminform and add %}
                                    $('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus()
                                {% endif %}
                            });
                        });
                    </script>
                {% endblock %}

            {# JavaScript for prepopulated fields #}
                {% prepopulated_fields_js %}
            </div>
        </div>

        <div class="form-actions">
            {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
        </div>
    </form>
    <script id="django-admin-form-add-constants" src="/static/admin/js/change_form.js" data-model-name="admingroup" async=""></script>
    <script id="django-admin-prepopulated-fields-constants" src="/static/admin/js/prepopulate_init.js" data-prepopulated-fields="[]"></script>
{% endblock %}
